package router

import (
	"easyShop/controller/api"
	"easyShop/middleware"
	"github.com/gin-gonic/gin"
)

func init() {

}

func Router(r *gin.Engine) bool {

	apiAuthGroup := r.Group("/api", middleware.UserAuthMiddleware())
	{
		// User about
		apiAuthGroup.GET("/user/getUserinfo", api.UserController{}.GetUserInfo)
		apiAuthGroup.GET("/user/getUserList", api.UserController{}.GetUserList)
		apiAuthGroup.GET("/user/checkToken", api.UserController{}.CheckToken)
		apiAuthGroup.POST("/user/updateUserInfo", api.UserController{}.UpdateUserInfo)
		apiAuthGroup.POST("/user/perfectUserProfile", api.UserController{}.PerfectUserProfile)
		apiAuthGroup.GET("/user/getAssets", api.UserController{}.GetAssets)

		// Order about
		apiAuthGroup.POST("/order/create", api.OrderController{}.Create)

		// Product Collection
		apiAuthGroup.POST("/product/collection", api.ProductCollectionController{}.AddCollection)

	}

	notApiAuthGroup := r.Group("/api")
	{
		// User about
		notApiAuthGroup.GET("/user/getBase64Captcha", api.UserController{}.GetBase64Captcha)
		notApiAuthGroup.GET("/user/checkCaptcha", api.UserController{}.CheckCaptcha)
		notApiAuthGroup.POST("/user/register", api.UserController{}.Register)
		notApiAuthGroup.POST("/user/login", api.UserController{}.Login)
		notApiAuthGroup.POST("/user/getOpenId", api.UserController{}.GetOpenId)
		notApiAuthGroup.POST("/user/authLogin", api.UserController{}.AuthLogin)

		// Product about
		notApiAuthGroup.GET("/product/getProductList", api.ProductController{}.GetProductList)
		notApiAuthGroup.GET("/product/getProductInfo", api.ProductController{}.GetProductInfo)
		notApiAuthGroup.GET("/product/batchCreateProduct", api.ProductController{}.BatchCreateProduct) // 批量生成测试数据，禁止生产环境使用

		// Banner about
		notApiAuthGroup.GET("/banner/getBannerList", api.BannerController{}.GetBannerList)

		// Upload about
		notApiAuthGroup.POST("/upload/uploadImage", api.UploadController{}.UploadImage)

		// Category about
		notApiAuthGroup.GET("/category/getRecommend", api.CategoryController{}.GetRecommend)

		// Config about
		notApiAuthGroup.GET("/config/getConfig", api.ConfigController{}.GetConfig)
		notApiAuthGroup.GET("/config/reloadConfig", api.ConfigController{}.ReloadConfig)

		// Test about
		notApiAuthGroup.GET("/test/TestRotation", api.TestController{}.TestRotation)
		notApiAuthGroup.GET("/test/TestDatabaseSources", api.TestController{}.TestDatabaseSources)

	}

	return true
}
